Repository navigation
Conversation
The generator wrote the JSON without a final newline, which the repository's .editorconfig requires. Profiles generated so far have been fixed up by hand or not at all. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
TL;DR: CPU profiles no longer drop MSR state in snapshots. With a CPU profile, snapshots and live migration only saved MSRs that the profile's required list contains. That list is frozen when the profile is generated, so MSRs that a newer KVM saves were silently lost. One example is IA32_DEBUGCTL, which KVM saves since 7.1: guests on the Sapphire Rapids profile lost bus-lock detection after a migration. MISC_FEATURES_ENABLES (CPUID faulting) was lost on both shipped profiles. Save every MSR in the hypervisor's MSR index list, as the Host profile does. The required list still has to be present on the host. VMX MSRs stay out of the snapshot without nested virtualization. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
The Cascade Lake profile sets FB_CLEAR in IA32_ARCH_CAPABILITIES. Newer hosts such as Sapphire Rapids do not, so the check only accepts the profile if the host reports the MDS, TAA, and MMIO stale data "_NO" bits. KVM clears TAA_NO when the host has no RTM, e.g. with tsx=off, because TAA needs TSX. So the Cascade Lake profile was refused on exactly the hosts that disable TSX, which the profiles expect. Do not require TAA_NO when the hypervisor does not report RTM. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
The SDM lists bit 63 as reserved, but the compatibility check treated it like a feature bit. A host that sets the bit was accepted for a profile that does not, even though a future meaning of the bit could be one that is unsafe when set. Require equality, as for the other reserved bits. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
The AVX10 feature bit (CPUID.7.1:EDX[19]) is set for every AVX10 version, and the version itself in CPUID.24H:EBX[7:0] was not checked. A CPU profile or a source VM with AVX10.2 was therefore accepted on a host with AVX10.1 only, and the guest would fault on AVX10.2 instructions. Require the version to be not greater on the destination. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
| // that the hypervisor does not permit setting (e.g. various VMX CTLS, IA32_VMX_CR0_FIXED, IA32_VMX_CR4_FIXED). | ||
| // Snapshot every MSR the hypervisor lists, as the Host profile does. | ||
| // `required` is frozen when the profile is generated, so limiting the | ||
| // snapshot to it would silently drop MSRs that newer hypervisors save |
There was a problem hiding this comment.
Not sure if this is a desirable policy?
CPUID.7.0:EBX[6] (FDP_EXCPTN_ONLY) and [13] (ZERO_FCS_FDS) are set when an x87 feature is absent. They were checked like normal feature bits, so a source with a bit set was refused on a destination without it, while the opposite direction was accepted. Neither direction matters: the hardware decides whether the x87 features are present, and KVM documents that the guest CPUID value of these bits has no effect. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
The "Reserved at 111" field of CPUID.24H:EBX was defined at bits 7:0, on top of the AVX10 version. The SDM places it at bits 18:16, which are always 111b if AVX10 is supported. As no definition covered bits 18:16, every profile generated on an AVX10 host such as Granite Rapids would have zeroed them. Guests then see an AVX10 CPU that contradicts the SDM. The shipped profiles have no AVX10 and do not change. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Three CPUID definitions placed fields on top of others, contrary to the SDM: - CPUID.7.1:ECX[1] RDT_A_ASYM was defined at bit 0. - CPUID.7.1:EDX[17] UIRET_UIF was defined at bit 15. - CPUID.23H.4:EBX was defined twice, with CNTR at bits 7:0 instead of 7:4 and XER at bits 23:17 instead of 23:16. All of these fields are forced to 0, so generated profiles give guests the same values as before. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Overlapping definitions let one definition silently override another. Overlapping bit ranges within a register left the uncovered bits zeroed. Two entries for the same CPUID register and sub-leaf, or for the same MSR, produce duplicate profile data, and only the first entry is applied. Check when the tables are built that the bit ranges of a register are disjoint and fit into it, that no two entries cover the same CPUID register and sub-leaf, and that no MSR is defined twice. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Correct three CPUID definitions against SDM 325462-093: - CPUID.4:ECX is the 32-bit number of cache sets, but bit 31 was not covered and therefore zeroed. - CPUID.18H.0:EBX/ECX/EDX are reserved. Only sub-leaves 1 and above describe TLBs, so the TLB fields no longer apply to sub-leaf 0. - CPUID.AH:EBX[12:8] and EDX[19:16] were missing. They stay 0 like the rest of the hidden PMU, but are now documented. Generated profiles now match the SDM. Guests see no difference under KVM: KVM reports 0 for leaf 0x18, and CPUID.4:ECX[31] is 0 on real hardware. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
The profiles hide RDT allocation, but passed the host's CPUID.10H.1/2 capacity bitmask length and bitmap through. They also inherited the XSAVE sub-leaves 19 to 63, whose XCR0 bits the SDM reserves. A profile generated on an APX host would thus describe XSAVE component 19 without advertising it in XCR0. Zero both, consistent with the feature bits. Under KVM, existing profiles already resolve to 0 for these fields. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
XSAVE sub-leaf 13 describes the HDC state component, not CET. Bits 9 and 10 of CPUID.FH.1:EAX shared one short name. Also fix two typos. The profiles do not change. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
The profiles hide protection keys (CPUID.7.0:ECX PKU and OSPKE), but still advertised the PKRU state component in CPUID.DH.0:EAX[9] and its size and offset in sub-leaf 9. Linux guests notice the mismatch and drop PKRU, but other guests could enable it in XCR0, because KVM only derives the allowed XCR0 bits from leaf 0xD. Hide the component too in profiles generated from now on. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Profiles forced CPUID.1:ECX[5] (VMX) to 1. KVM only reports VMX when kvm_intel's nested parameter is enabled, and the profile is checked against the host before CHV clears VMX for VMs without nested virtualization. On hosts with nested=0, every VM using such a profile fails to start, even with nested=off. Take the bit from the host in profiles generated from now on. CHV still clears it for VMs without nested virtualization, and migrations still require it on the destination if the source has it. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
CPUID.7.0:EBX[6] (FDP_EXCPTN_ONLY) and [13] (ZERO_FCS_FDS) came from the host, so the guest CPUID of a profile differed between hosts. The hardware decides about the x87 behavior either way, and the KVM docs recommend to always set both bits in guest CPUID. Do so in profiles generated from now on, which makes them identical on all hosts. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Profiles hide WAITPKG, but still allowed the "enable user wait and pause" control in IA32_VMX_PROCBASED_CTLS2, as the Sapphire Rapids profile does. KVM clears that control when KVM_SET_CPUID2 hides WAITPKG, but CHV writes the profile's VMX MSRs afterwards and so re-enables it. With nested virtualization, an L1 hypervisor can then let L2 run UMWAIT and TPAUSE. Hide the control. Do the same for "enable ENCLS exiting", as SGX is hidden too: a profile generated on a host with SGX would otherwise make KVM reject VMs with nested virtualization on every host without SGX. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Two VMX capability values describe the KVM version rather than the CPU, yet profiles inherited them from the generation host: - IA32_VMX_VMCS_ENUM is computed from the VMCS fields that KVM emulates, and KVM accepts any value on writes. A profile generated with a newer KVM could thus announce VMCS fields that the running KVM does not implement. Take it from the host instead. - IA32_VMX_BASIC[58] (VMX nested-exception support, for FRED) was not defined and thus inherited. Once KVM reports it, a profile generated with that KVM would be rejected by older KVM versions. Hide it, as FRED is not exposed. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
- IA32_BARRIER is enumerated by CPUID.7.1:EAX[27], but its compile time check looked at sub-leaf 0, where EAX holds the maximum sub-leaf. The check thus verified nothing. - The IA32_MCU_CONTROL range ended at decimal 1406 instead of 0x1406, so it was empty. - IA32_ARCH_CAPABILITIES[62] (ITS_NO) is set if the system is not affected, as Linux and KVM use it. The description copied the inverted wording of SDM 325462-093. - IA32_MCG_CAP is not zeroed for CPU profiles: CHV does not configure machine checks, so KVM reports its default. The profiles do not change. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
TL;DR: v2 profiles carry the definition fixes, v1 stays as it was. The existing profiles cannot change in place: CHV checks a migrated or restored VM's CPUID against the profile on the destination, so e.g. hiding PKRU would refuse every VM that was started with the old data. Add sapphire-rapids-v2 and cascade-lake-v2 for new VMs instead. Compared to v1, they: - take the VMX bit from the host, so they work with kvm_intel nested=0, - hide the PKRU XSAVE component, as PKU is hidden, - always set the x87 defeature bits CPUID.7.0:EBX[6] and [13], - hide the "enable user wait and pause" VMX control (Sapphire Rapids), - take IA32_VMX_VMCS_ENUM from the host, - match the SDM for CPUID.4:ECX[31], leaf 0x18 sub-leaf 0, the RDT sub-leaves, and the XSAVE sub-leaves 19 and above. Guests under KVM see no difference there. The original generation hosts were not available. Both profiles were re-derived from the v1 data: the generation host's KVM values were reconstructed from it, and the generator then ran with the current definitions. With the previous definitions, the same procedure reproduces v1 exactly. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
3b97396 to
baf412c
Compare
This is intentional behavior: Only MSRs that are compatible with the profile should be snapshotted/transferred, because otherwise they are not compatible with the profile/lowest common denominator in your fleet anyway and setting them will fail. An earlier version on our fork even made it impossible to access such MSRs, but the MSR filter logic was complex and not desired upstream.
I know it is reserved in the SDM, but I actually found it documented here: https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/branch-history-injection.html
I think that this was already the case.
This is on my radar and needs to be two separate PRs.
It already works when nested=off. It is however more consistent/technically correct to use passthrough here (already done in our upstreaming branch(es)).
Then we cannot migrate to older instances whose compatibility checks do not ignore those de-feature bits. If it is policy never to migrate to older, then that is fine, but it would make more sense for the VMM to set this and not CPU profiles.
This does not sound correct to me.
It is good to check this, but I realized that checking these large tables at compile time can make the IDE sluggish when working in that file. We do this as a unit test in the upstreaming branch(es).
Were these generated on real deployments? I think we should not introduce new profiles now, unless critical, and rather re-generate profiles once the upstreaming work is completed. We should then see if we can just replace the existing profiles directly (provided that the impact is not too severe), because we want to maintain as few profiles as possible. The other points in the overview seem reasonable, but I would have to think about them a bit more to be sure. |
|
@olivereanderson thanks! Could you please also write down the fixes that are good and we should keep? |
|
Could you investigate this one a bit more: These two can also be upstreamed pretty much right away:
I think we should ignore the rest and rather focus on upstreaming the CPU profile generation tool itself as that effort addresses most of the other points anyway. |
I asked Claude with the Opus 5.5. model to check everything regarding CPUID, MSRs, and the adjustments for CPU profiles. Seems to be not critical but I think we should at least take a look.
Pipeline: https://gitlab.cyberus-technology.de/cyberus/cloud/libvirt/-/merge_requests/332/pipelines
What changes
Runtime, for all profile VMs:
IA32_DEBUGCTL(bus-lock detection) on hosts with Linux 7.1 or newer andMISC_FEATURES_ENABLES(CPUID faulting) everywhere.tsx=off.IA32_ARCH_CAPABILITIESbit 63 is treated as reserved.CPUID compatibility check (also for VMs without a profile):
New profiles
sapphire-rapids-v2andcascade-lake-v2. The existing profiles stay byte-identical, because changing them would block migrating running VMs. Compared to v1, v2:kvm_intel nested=0,VMCS_ENUMfrom the running host,Tooling: the definition tables are corrected against the SDM, a compile-time check rejects overlapping or duplicate definitions, and the generator writes the final newline.
Confidence
Existing VMs
sapphire-rapidsorcascade-lakemigrate to this version as before, because the v1 data is unchanged. From then on, all MSRs are migrated. State lost on earlier migrations returns only after a guest reboot.nested=0limitation. New VMs should use the-v2profiles. Switching a VM needs a restart, and the guest then sees a slightly different CPU model.